package com.pizzaonline.JDBC;

import com.pizzaonline.JDBC.DataBase;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBControler {
	
	//Méthode calculant la somme des prix des ingrédients
	public static float getSommeIngredients(String[] ingredients, DataBase db){
		float somme = 0;
		float temp;
		String ingredient;
		ResultSet rs;
		String sql="";
		try{
			db.connexionBD();
			for(int i=0; i<ingredients.length;i++){
				ingredient = ingredients[i];
				rs = db.select("prix_unitaire","stock","nom='"+ingredient+"'");
				if(rs.next()){
					temp = rs.getFloat("prix_unitaire");
					somme+= temp;
				}
			}
			db.closeConnection();
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		return somme;
	}
	
}
